package com.shuqi.model;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;

import com.shuqi.application.ShuqiApplication;
import com.shuqi.common.MyTask;
import com.shuqi.common.Urls;
import com.shuqi.common.utils.HttpCommonParamsUtils;
import com.shuqi.model.manager.MyAccountManager;
import com.shuqi.model.net.HttpRequest;
import com.shuqi.model.net.UrlManager;
import com.shuqi.model.net.listener.HttpRequestListener;
import com.shuqi.model.parse.parser.VerifyBookDownUrlPaser;

/**
 *  校验书籍下载地址 
 * @author yanghuawei
 * 
 */
public class VerifyBookDownLoadUrlModel extends ModelBase implements HttpRequestListener {
    private HttpRequest httpRequest;
    private String bookId;

    public VerifyBookDownLoadUrlModel(String bookId) {
        this.bookId = bookId;
    }

    @Override
    public void action(int actionCode, Object object) {
        fireEvent(actionCode, object);
    }

    @Override
    public List<BasicNameValuePair> setParams() {
        return HttpCommonParamsUtils.getShuQiBasicParams(MyAccountManager.getInstance(ShuqiApplication.getContext()).getUserId());
    }

    @Override
    public String getRequestUrl() {
        return Urls.getVerifyBookDownLoadUrlUrl(bookId);
    }

    @Override
    public void onDestroy() {
        if (httpRequest != null) {
            httpRequest.abort();
        }
    }

    @Override
    public void loadData(Object... objs) {
        httpRequest =
                new HttpRequest(ShuqiApplication.getContext(), UrlManager.COLUMN_DOMAIN_READ, getRequestUrl(), setParams(),
                        this);
        httpRequest.setDataParseAdapter(new VerifyBookDownUrlPaser());
        MyTask.runInBackground(httpRequest, true);
    }
}
